<template>
	<view class="listBox">
		<view class="header">
			<!-- 固定头部 -->
			<view class="fixed">
				<view class="fixedBox">
					<view :class="reportShow == 2 ? 'now' : ''" @click="clickReport(2)">现状评估</view>
					<view :class="reportShow == 3 ? 'risk' : ''" @click="clickReport(3)">风险评估</view> 
					<view :class="reportShow == 1 ? 'summary' : ''" @click="clickReport(1)">评估汇总</view>
				</view>
			</view>
		</view>
		<view class="mainContent" v-if="list.length > 0">
			<uni-swipe-action>
				<view>
					<uni-swipe-action-item  v-for="(item,index) in list" :key="index" :right-options="reportShow == 2 && item.mark == 1 ? options : [] " @click="bindClick(item)">
						<view class="item" >
							<div class="item-l">
								<image mode="aspectFill" src="../../../static/img/monitor/archived.png"></image>
								<!-- <image mode="aspectFill" :src="!item.sources || item.sources == 2 ?'../../../static/img/monitor/not-archived.png':'../../../static/img/monitor/archived.png'"></image> -->
								<text>{{item && item.status == 2 ? item.healthName && item.healthName || item.userName: item && item.userName }}</text>
							</div>
							<div class="item-c" @click="toView(item)" v-if="reportShow == 2">
								<p>中医体质评估</p>
								<p>评估编号：{{!item.status || item.status == 1?'待评估':item.sn}}</p>
								<p>辨识结果：{{!item.status || item.status == 1?'待评估':item.string}}</p>
							</div>
							<div v-if="reportShow == 2" :class="['item-r',!item.status || item.status == 2?'not-archived':item.status == 1 ? 'normal' : '', item.type == 2 ? 'archived' : '' ]">
								{{!item.status || item.status == 1?'已保存': item.type == 2 ? '已评估' : '待评估'}}
								<span v-if="item.url" class="readReport" @click="read1(item)">查看报告</span>
							</div>
							
							<div class="item-c" @click="RisksToView(item)" v-if="reportShow == 1">
								<p>健康风险评估汇总</p>
								<p>评估编号：{{item.sn}}</p>
								<p>评估时间：{{!item.status || item.status == 1?'待评估':item.modifiedDate}}</p>
							</div>
							<div  v-if="reportShow == 1" :class="['item-r',!item.status || item.status == 2 ? 'archived' : 'normal']">{{!item.status || item.status == 2?'已存档': '未存档'}}</div>
							
							<div class="item-c" v-if="reportShow == 3">
								<p>疾病风险评估</p>
								<p>评估编号：{{item.reportNo}}</p>
								<p>评估时间：{{!item.status || item.status == 1?'待评估':item.updateTime}}</p>
							</div>
							<div  v-if="reportShow == 3" :class="['item-r',!item.status || item.status == 2 ? 'archived' : 'normal']">
								{{!item.status || item.status == 2?'已存档': '未存档'}}
								<span v-if="item.status == 2" class="readReport" @click="read(item)">查看报告</span>
							</div>
						</view>
					</uni-swipe-action-item>
				</view>
			</uni-swipe-action>
		</view>
		<view class="noneChating" v-if="list.length <= 0">
			<image src="../../../static/img/index/chattingNone.png"></image>
			<view>暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {filterData2} from '@/static/js/filter.js';
	import uSwipeActionItem from "@/components/uni-swipe-action-item/uni-swipe-action-item.vue";
	import uniSwipeAction from "@/components/uni-swipe-action/uni-swipe-action.vue";
	export default {
		data () {
			return {
				pageIndex: 1,
				pageSize: 10,
				list: [],
				Risks: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' ,// 删除按钮背景  红的
					}
				}],
				reportShow: 2,
				page:1,
				deleteList:'',
				nullData: false,
			}
		},
		onLoad(options){
			if(options.type == 2){
				this.reportShow = 3
				this.getlist(3,{pageIndex:this.pageIndex,pageSize:this.pageSize,type:3})
				return;
			}
			this.getlist(2,{pageIndex:this.pageIndex,pageSize:this.pageSize,type:2})
		},
		onReachBottom() {
			console.log(this.nullData)
			if(this.nullData){
				return;
			}
			this.page = this.page + 1
			this.getlist(this.reportShow,{pageIndex:this.page,pageSize:this.pageSize,type:this.reportShow})
		},
		methods:{
			filterData2,
			clickReport(e) {
				this.reportShow = e;
				this.nullData = false
				this.page = 1
				this.list = []
				this.getlist(e,{pageIndex:this.pageIndex,pageSize:this.pageSize,type:e})
			},
			// 获取中医体质列表
			getlist(e,v){
				// {pageIndex:this.pageIndex,pageSize:this.pageSize,type:e}
				this.$api.HealthRisksList(v).then((res) => {
					if(res.data.returnCode == '200') {
						var data = []
						if(res.data.result){
							if(res.data.result.appConstitutionEntityPage){
								data = res.data.result.appConstitutionEntityPage.elements
							}else if(res.data.result.appPutInAssessEntityPage){
								data = res.data.result.appPutInAssessEntityPage.list
							}else{
								data = res.data.result.appHealthRisksEntityPage && res.data.result.appHealthRisksEntityPage.elements
							}
						}
						var dataType = data && data.map((a) => {
							if(a.constitution){
								const constitution = JSON.parse(a.constitution)
								if(!constitution[0] && !constitution[1] && !constitution[2] && !constitution[3]){
									a.string = ''
								}else if(!constitution[3] && constitution[0]) {
									a.string = '为'+constitution[0]+'体质'
								}else{
									a.string = '为'+constitution[0]+(constitution[0] == '偏颇体质'?',':'体质,') +(constitution[1] ? '以'+constitution[1]+'为主,' : '' ) + ( constitution[2] ? '兼'+constitution[2]+'体质,' : '') + '有'+constitution[3]+'倾向'
								}
							}
							return a
						}) || []
						
						if(this.deleteList == 1) {
							this.list = []
							this.list = dataType
							this.deleteList = ''
						}else {
							this.list = this.list ? this.list.concat(dataType) : dataType
						}
						var totalCount = 0
						if(res.data.result && (res.data.result+'' != '{}')){
							if(res.data.result.appConstitutionEntityPage){
								totalCount = res.data.result.appConstitutionEntityPage.totalCount
							}else if(res.data.result.appPutInAssessEntityPage){
								totalCount = res.data.result.appPutInAssessEntityPage.totalCount
							}else{
								totalCount = res.data.result.appHealthRisksEntityPage && res.data.result.appHealthRisksEntityPage.totalCount || 0
							}
						}
						if(this.list.length >= totalCount){
							this.nullData = true;
						}
					}
				
				})
			},
			toView(e) {
				uni.navigateTo({
					url:'/pages/monitor/tcm/syndrome?id='+e.id+'&status='+e.status
				})
			},
			RisksToView(e) {
				uni.navigateTo({
					url:'/pages/monitor/summy/toView?id='+e.id+'&userId='+e.userId
				})
			},
			// 删除中医体质列表
			bindClick(e) {
				const id = e.id;
				this.$api.questionnaireDel(id).then((res) => {
					if(res.data.returnCode == '200') {
						uni.showToast({
							title: '删除成功',
							icon: 'none'
						})
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist(2,{pageIndex:this.pageIndex,pageSize:this.pageSize,type:2})
					}
				})
			},
			read(item){
				window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+item.reportUrl
			},
			read1(item){
				if(item.url) {
					window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+item.url
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/monitor/tcm/list.scss';
	.readReport{
		display: inline-block;
		width: 126upx;
		height: 46upx;
		background: #38CB97;
		border-radius:6upx;
		color: #fff;
		text-align: center;
		line-height: 46upx;
		font-weight: normal;
		margin-top: 40upx;
	}
	.noneChating {
		padding-top: 228upx;
		image {
			display: block;
			margin: 0 auto;
			width: 260upx;
			height: 154upx;
		}
		view {
			margin: 24px auto;
			text-align: center;
			color: #333333;
			font-size: 13px;
		}
	}
</style>
